﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UcAsp.Models;
namespace UcAsp.Controllers
{
    public class HomeController : Controller
    {
        private UcAspNetEntities entities = new UcAspNetEntities();
        public ActionResult Index()
        {
            HomeModel model = new HomeModel();
            model.Fashion=(from c in entities.Articless
                        join m in entities.Categoriess
                        on c.CategorieID equals m.ID
                        where m.ParentID == 2&&c.IsRelease==true
                        orderby c.Rate descending
                        select c).Take(7).ToList();
            model.Action = (from c in entities.Articless
                            join m in entities.Categoriess
                            on c.CategorieID equals m.ID
                            where m.ParentID == 7 && c.IsRelease == true
                            orderby c.Rate descending
                            select c).Take(8).ToList();
            model.Answer = (from c in entities.Articless
                            where c.CategorieID == 17 && c.IsRelease == true
                            orderby c.IsRecommend descending, c.Rate descending
                           select c).Take(8).ToList();
            model.Talent= (from c in entities.Articless
                           where c.CategorieID == 13 && c.IsRecommend == true && c.IsRelease == true
                           orderby c.Rate descending
                           select c).Take(6).ToList();
            model.Vedio = (from c in entities.Articless
                           where c.CategorieID == 15 && c.IsRelease == true
                           orderby c.Rate descending
                            select c).Take(6).ToList();
            var query = (from c in entities.Articless
                           join m in entities.Categoriess
                           on c.CategorieID equals m.ID
                           where m.ParentID == 21 && c.IsRelease == true
                         orderby c.Rate descending
                           select c).Take(4).ToList();
            List<Articles> list=new List<Articles>();
            foreach (Articles a in query)
            {
                a.Categoriess = entities.Categoriess.FirstOrDefault(o => o.ID == a.CategorieID);
                list.Add(a);
            }
            model.Works = list;
            return View(model);
        }

        public ActionResult About()
        {
            return View();
        }
        public ActionResult information(string name, string themes)
        {
            Categories cate = entities.Categoriess.FirstOrDefault(o => o.CategorieName == name);
            return View(themes, cate);
        }
    }
}
